// 此处只有两个API,全局导入API
export const mixin = {
    data() {
       return {
           listLoading: false,
           total: 0,
           list: [],
           btnLoading: false
       }
    },
    created() {
        // 备份查询条件
        this.listQueryCopy = _.cloneDeep(this.listQuery)
        // 初始化数据
        this.searchList()
    },
    methods: {
        // 基础查询方法
        getList(listQuery) {
            this.listLoading = true
            this.searchListAll(listQuery).then((res) => {
                this.list = res.data.list
                this.total = res.data.total
                this.listLoading = false
            })
        },
        // 查询
        searchList() {
            const listQuery = this.setListQuery(_.cloneDeep(this.listQuery))
            this.getList(listQuery)
        },
        // 重置
        resetSearch() {
            this.listQuery = this.setListQuery(_.cloneDeep(this.listQueryCopy))
            this.getList(this.listQuery)
        },
        /**
         * 查询条件的二次处理,前端格式与后台不一致
         */
        setListQuery(query) {
            const newQuery = {
                'newQueryVos': [],
                "pageSize": 10,
                "pageNum": 1
            }
            _.forEach(query, function(value, key) {
                if(key !== 'pageNum' || key !== 'pageSize') {
                    newQuery.newQueryVos.push({
                        'newQueryName': key,
                        'newQueryValue': value
                    })
                }
            })
            return newQuery
        },
        // 页面跳转
        toPath(url) {
            this.$router.push(url)
        },



        // 数据保存方法
        saveNewMedia(data, message) {
            this.$confirm(`此操作将${message}, 是否继续?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.btnLoading = true
                this.saveNewMedia(data).then((res) => {
                    this.$message({
                        type: 'success',
                        message: `${txt}成功!`
                    })
                    this.btnLoading = false
                }).catch(() => {
                    this.btnLoading = false
                })
            })

        }
    }
}